<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <!--        <a-button type="primary" @click="handleCreate"> 新增成员 </a-button>-->
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                // icon: 'clarity:note-edit-line',
                label: '查看',
                color: 'success',
                onClick: handleView.bind(null, record),
              },
              {
                label: '关闭',
                color: 'error',
                popConfirm: {
                  title: '是否关闭该订单？',
                  placement: 'left',
                  confirm: handleDelete.bind(null, record),
                },
              },
              // {
              //   icon: 'ant-design:delete-outlined',
              //   color: 'error',
              //   popConfirm: {
              //     title: '是否确认删除',
              //     placement: 'left',
              //     confirm: handleDelete.bind(null, record),
              //   },
              // },
            ]"
          />
        </template>
        <template v-if="column.dataIndex === 'isReturn'">
          <div style="width: 100%; cursor: pointer" @click="openUserModal(record)">
            <span v-if="record.isReturn == 1" style="color: green">是(点击看明细)</span>
            <span v-else="record.isReturn == 0">否</span>
          </div>
        </template>
      </template>
    </BasicTable>
    <FormModal @register="register" @success="handleSuccess"/>
    <OrderListModal @register="orderModal[0]"/>


  </div>
</template>
<script lang="ts" setup>
import {BasicTable, useTable, TableAction} from '@/components/Table';
import {ref, onMounted} from 'vue';
import {useRoute} from 'vue-router';
import {purchaseOrderTableListApi, priceTableListApi} from '@/api/sys/msUser';

const route = useRoute();
import OrderListModal from './OrderListModal.vue';

import FormModal from './FormModal.vue';
import {columns, searchFormSchema} from './role.data';
import {useMessage} from '@/hooks/web/useMessage';
import {useModal} from '@/components/Modal';

defineOptions({name: 'userNoteList'});
const {createMessage} = useMessage();
const loading = ref(false);

const userName = ref(route.params?.userName);

const [register, {openModal, closeModal}] = useModal();

const orderModal = useModal();


var allList=[
  //国际标准
  {
    code:"ISO13074",
    name:"指针式石英钟—机心与指针的配合尺寸",
    type:1,//对应tabs数组下标
    date:"2012-07-15",//发布时间
    type_name:"国际"
  },
  {
    code:"ISO19235:2015",
    name:"指针式石英钟-走时精度",
    type:1,//对应tabs数组下标
    date:"2015-10-30",//发布时间
    type_name:"国际"
  },
  {
    code:"ISO23346:2020",
    name:"电波钟—信号接收测试方法",
    type:1,//对应tabs数组下标
    date:"2020-07-31",//发布时间
    type_name:"国际"
  },
  //国家标
  {
    code:"GB/T9820.2-2008",
    name:"计时学术语 第2部分：技术和商业用定义",
    type:2,//对应tabs数组下标
    date:"2009-02-28",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T4048-2008",
    name:"计时仪器手表壳与表带连接部位的尺寸系列",
    type:2,//对应tabs数组下标
    date:"2009-02-28",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T30416-2013",
    name:"钟表售后维修服务技术规范",
    type:2,//对应tabs数组下标
    date:"2014-01-31",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T33724-2017",
    name:"钟表评定石英手表精度的步骤",
    type:2,//对应tabs数组下标
    date:"2017-06-30",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T33727-2017",
    name:"指针式石英钟机心与指针的配合尺寸",
    type:2,//对应tabs数组下标
    date:"2017-06-30",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T34837-2017",
    name:"计时仪器零部件分类、名称和编号 石英手表机心",
    type:2,//对应tabs数组下标
    date:"2018-03-15",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T34839-2017",
    name:"计时仪器 柄头和密封管的设计和尺寸",
    type:2,//对应tabs数组下标
    date:"2018-03-15",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T36425-2018",
    name:"表壳体及其附件金合金覆盖层的颜色范围和名称",
    type:2,//对应tabs数组下标
    date:"2018-06-07",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T36434-2018",
    name:"复杂机械手表机心  万年历和打簧机构零部件的名称",
    type:2,//对应tabs数组下标
    date:"2018-06-07",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T38021-2019",
    name:"指针式石英钟-走时精度",
    type:2,//对应tabs数组下标
    date:"2020-03-01",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T39141.1-2020",
    name:"无机和蓝宝石手表玻璃第1部分：尺寸和公差",
    type:2,//对应tabs数组下标
    date:"2020-10-11",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T39141.2-2020",
    name:"无机和蓝宝石手表玻璃第2部分：用粘胶或密封圈装到表壳上的配合",
    type:2,//对应tabs数组下标
    date:"2020-11-19",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T22778-2021",
    name:"液晶数字式石英秒表",
    type:2,//对应tabs数组下标
    date:"2021-08-20",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T40359-2021",
    name:"计时仪器 光致发光涂层 试验方法和要求",
    type:2,//对应tabs数组下标
    date:"2021-08-20",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T40673-2021",
    name:"计时仪器 辐射发光涂层检验条件",
    type:2,//对应tabs数组下标
    date:"2021-10-11",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T39141.3-2022",
    name:"无机和蓝宝石手表玻璃 第3部分：定性标准和试验方法",
    type:2,//对应tabs数组下标
    date:"2023-03-01",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T18828-2022",
    name:"钟表 潜水表",
    type:2,//对应tabs数组下标
    date:"2023-03-01",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T32484-2022",
    name:"表壳体及其附件 气相沉积镀层",
    type:2,//对应tabs数组下标
    date:"2023-03-01",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T26716-2023",
    name:"钟表 防磁手表",
    type:2,//对应tabs数组下标
    date:"2023-08-06",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T42826-2023",
    name:"电波钟 信号接收测试方法",
    type:2,//对应tabs数组下标
    date:"2023-08-06",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T42947-2023",
    name:"手表机心的可靠性试验方法",
    type:2,//对应tabs数组下标
    date:"2023-08-06",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T42951-2023",
    name:"计时仪器 硬材料制造的手表外观件一般要求和试验方法",
    type:2,//对应tabs数组下标
    date:"2023-08-06",//发布时间
    type_name:"国家"
  },
  {
    code:"GB/T42951-2023",
    name:"计时仪器 硬材料制造的手表外观件一般要求和试验方法",
    type:2,//对应tabs数组下标
    date:"2023-08-06",//发布时间
    type_name:"国家"
  },
  //行业标准
  {
    code:"QB/T1249-2013",
    name:"机械手表",
    type:3,//对应tabs数组下标
    date:"2014-01-31",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T4777-2014",
    name:"指针式石英钟机心与钟壳的配合尺寸",
    type:3,//对应tabs数组下标
    date:"2014-10-30",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T5031-2017",
    name:"手表壳 金属按钮",
    type:3,//对应tabs数组下标
    date:"2017-08-15",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T5032-2017",
    name:"手表带用连接件",
    type:3,//对应tabs数组下标
    date:"2017-08-15",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T5174-2017",
    name:"表用高碳钢带",
    type:2,//对应tabs数组下标
    date:"2018-05-31",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T5175.1-2017",
    name:"手表外观件佩戴环境试验方法 第1部分：通用要求",
    type:3,//对应tabs数组下标
    date:"2018-05-31",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T5175.2-2017",
    name:"手表外观件佩戴环境试验方法 第2部分：化妆品试验",
    type:3,//对应tabs数组下标
    date:"2018-05-31",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T1038-2020",
    name:"指针式石英钟用单相永磁步进电动机的技术要求和试验方法",
    type:3,//对应tabs数组下标
    date:"2020-08-31",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T1540-2020",
    name:"钟用黄铜线",
    type:3,//对应tabs数组下标
    date:"2020-08-31",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T1542-2020",
    name:"钟表用铅黄铜棒与线",
    type:3,//对应tabs数组下标
    date:"2020-08-31",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T2405-2020",
    name:"钟表宝石元件",
    type:3,//对应tabs数组下标
    date:"2020-08-31",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T 1939-2021",
    name:"电风扇用机械式定时器",
    type:3,//对应tabs数组下标
    date:"2022-03-01",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T2269-2021",
    name:"电烤箱用机械定时器",
    type:3,//对应tabs数组下标
    date:"2022-04-01",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T4775-2023",
    name:"表壳体及附件 人工汗和盐雾耐腐蚀性能试验方法",
    type:3,//对应tabs数组下标
    date:"2022-04-01",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T5822-2023",
    name:"表壳体及其附件 湿热试验和热冲击试验",
    type:3,//对应tabs数组下标
    date:"2023-04-21",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T2540-2023",
    name:"皮革表带",
    type:3,//对应tabs数组下标
    date:"2023-04-21",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T1541-2023",
    name:"钟用钢棒与钢丝",
    type:3,//对应tabs数组下标
    date:"2023-04-21",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T1539-2023",
    name:"钟表用黄铜板与带",
    type:3,//对应tabs数组下标
    date:"2023-04-21",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T4160-2023",
    name:"使用宝石和贵金属的手表",
    type:3,//对应tabs数组下标
    date:"2023-04-21",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T2022-2023",
    name:"表用镍锌白铜棒",
    type:3,//对应tabs数组下标
    date:"2023-04-21",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T2258-2023",
    name:"机械式响铃定时器",
    type:3,//对应tabs数组下标
    date:"2023-04-21",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T2662-2023",
    name:"电动机式家用微波炉定时器",
    type:3,//对应tabs数组下标
    date:"2023-04-21",//发布时间
    type_name:"行业"
  },
  {
    code:"QB/T5957-2023",
    name:"机械手表操作件疲劳试验",
    type:3,//对应tabs数组下标
    date:"2024-07-01",//发布时间
    type_name:"行业"
  },
]

const [registerTable, {reload}] = useTable({
  title: '费用明细列表',
  api: priceTableListApi,
  columns,
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
    autoSubmitOnEnter: true,
  },
  useSearchForm: true,
  showTableSetting: true,
  bordered: true,
  showIndexColumn: false,
  actionColumn: {
    width: 110,
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
  },
});

function handleCreate() {
  openModal(true, {
    isUpdate: false,
  });
}

function format(seconds) {
  //秒转化为分钟格式
  let s = Math.trunc(seconds);
  let minInt = Math.floor(s / 60);
  let min = minInt >= 10 ? minInt : '00' + minInt;
  s -= 60 * min;
  let sec = s >= 10 ? s : '00' + s;
  return min + ':' + sec;
}

function handleEdit(record: Recordable) {
  openModal(true, {
    record,
    isUpdate: true,
  });
}

function handleView(record: Recordable) {
  let url = record.mp3Url ? record.mp3Url : record.remoteUrl;
  // let url=record.remoteUrl;
  window.open(url);
}

function handleDelete(record: Recordable) {
  //console.log(record);

  deleteApi(record)
    .then((res) => {
      createMessage.success(res.message);
    })
    .catch((res) => {
      createMessage.error(res.message);
    })
    .finally(() => {
      reload();
    });
}

function handleSuccess() {
  reload();
}

const arrHeader = [
  {
    key: 'userName',
    value: '姓名',
  },
  {
    key: 'levelName',
    value: '职级',
  },
];

function getHeadArr() {
  let arr = [];
  arrHeader.forEach((r) => {
    arr.push(r.value);
  });
  return arr;
}

function changeSubmitArr(results) {
  let data = {
    list: [],
  };
  let list = [];
  results.forEach((r) => {
    let json = {};
    for (let key in r) {
      arrHeader.forEach((e) => {
        if (e.value == key) {
          json[e.key] = r[key];
        }
      });
    }
    data.list.push(json);
  });
  return data;
}

function openUserModal(record: Recordable) {
  orderModal[1].openModal(true, record);
}
</script>
